package com.sise.wangzhan.command;

import com.netflix.hystrix.HystrixCommand;
import com.netflix.hystrix.HystrixCommandGroupKey;

/**
 * @Classname ThreadCommand
 * @Description TODO    隔离机制
 * @Date 2020/4/30 10:06
 * @Created by wangzhan
 */
public class ThreadCommand extends HystrixCommand<String> {

    int index;
    public ThreadCommand(int index) {
        super(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("ExampleGroup")));
        this.index = index;
    }

    @Override
    protected String run() throws Exception {
        Thread.sleep(500);
        System.out.println("执行方法，当前索引："+index);
        return "";
    }

    @Override
    protected String getFallback() {
        System.out.println("执行fallback，当前索引："+index);
        return "";
    }
}
